﻿$(function () {
    var self = this;

    this.adjustWidth = function () {
        $(".post img").each(function (index) {
            var post = $(this).parents(".post").first();
            var postMargin = parseInt(post.css("marginLeft")) + parseInt(post.css("marginRight"));
            var maxWidth = $(window).width() - postMargin;
            if ($(this).width() > maxWidth) {
                var scale = maxWidth / $(this).width();
                var newWidth = maxWidth;
                var newHeight = scale * $(this).height();
                $(this).width(newWidth);
                $(this).height(newHeight);
            }
        });
    };

    self.adjustWidth();
    $(window).resize(self.adjustWidth);
 
});